/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.belfalas.simy86.operadores;

import org.belfalas.simy86.Operador_Stat;
import org.belfalas.simy86.Y86;

/**
 *
 * @author belfalas
 */
public abstract class OP1 extends Operador{

    @Override
    public void fetch(org.belfalas.simy86.Operador_Stat stat) {
        stat.reg = Y86.memoria.readUnsignedByte(stat.pc+1);
        stat.rA = getRA(stat.reg);
        stat.rB = getRB(stat.reg);
        if (stat.rA != null) stat.rA.incUsage();
        if (stat.rB != null) stat.rB.incUsage();
        stat.valP = stat.pc+2;
        stat.predicted_pc = stat.valP;
    }

    @Override
    public void decode(org.belfalas.simy86.Operador_Stat stat) {
        if (stat.rA != null) stat.valA = stat.rA.reg;
        if (stat.rB != null) stat.valB = stat.rB.reg;        
    }

    @Override
    public void execute(Operador_Stat stat) {
        if (stat.rA != null) stat.rA.decUsage();
    }

    @Override
    public void memory(org.belfalas.simy86.Operador_Stat stat) {
        
    }

    @Override
    public void writeback(org.belfalas.simy86.Operador_Stat stat) {
        stat.rB.reg = stat.valE;
        stat.rB.decUsage();
        //PC.position = stat.valP;
    }
    
    abstract void setCC(org.belfalas.simy86.Operador_Stat stat);
}
